package com.master.demo.controller.sys;

import com.master.common.annotation.Log;
import com.master.common.api.IPageInfo;
import com.master.common.api.Query;
import com.master.common.api.ResponseInfo;
import com.master.common.enums.BusinessTypeEnum;
import com.master.demo.framework.base.BaseController;
import com.master.demo.sys.constant.SysLogTypeConstant;
import com.master.demo.sys.pojo.command.AdvertisingCommand;
import com.master.demo.sys.pojo.vo.AdvertisingVO;
import com.master.demo.sys.service.IAdvertisingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 *  广告位配置接口
 *
 * @author: Yang
 * @date: 2023-06-15
 * @version: 1.0.0
 * Copyright Ⓒ 2022 Master Computer Corporation Limited All rights reserved.
 */
@RestController
@RequestMapping("/sys/advertising" )
public class AdvertisingController extends BaseController {
    @Autowired
    private IAdvertisingService advertisingService;

    /**
     * 查询广告位配置分页列表
     *
     * @author: Yang
     * @date: 2023-06-15
     * @version: 1.0.0
     */
    @GetMapping("/page" )
    @PreAuthorize("hasAuthority('sys:advertising:list')")
    public ResponseInfo<IPageInfo<AdvertisingVO>> pageAdvertising(@RequestParam Map map) {
        return advertisingService.pageAdvertising(new Query(map, true));
    }

    /**
     * 查询广告位配置列表
     *
     * @author: Yang
     * @date: 2023-06-15
     * @version: 1.0.0
     */
    @GetMapping("/list" )
    @PreAuthorize("hasAuthority('sys:advertising:list')")
    public ResponseInfo<List<AdvertisingVO>> listAdvertising(@RequestParam Map map) {
        return advertisingService.listAdvertising(new Query(map));
    }

    /**
     * 获取广告位配置详细信息
     *
     * @author: Yang
     * @date: 2023-06-15
     * @version: 1.0.0
     */
    @GetMapping(value = "/{id}" )
    @PreAuthorize("hasAuthority('sys:advertising:query')")
    public ResponseInfo<AdvertisingVO> getAdvertisingById(@PathVariable("id" ) Long id) {
        return advertisingService.getAdvertisingById(id);
    }

    /**
     * 新增广告位配置
     *
     * @author: Yang
     * @date: 2023-06-15
     * @version: 1.0.0
     */
    @PostMapping
    @PreAuthorize("hasAuthority('sys:advertising:save')")
    @Log(type = SysLogTypeConstant.ADVERTISING, businessType = BusinessTypeEnum.INSERT)
    public ResponseInfo saveAdvertising(@Validated @RequestBody AdvertisingCommand command) {
        return advertisingService.saveAdvertising(command);
    }

    /**
     * 修改广告位配置
     *
     * @author: Yang
     * @date: 2023-06-15
     * @version: 1.0.0
     */
    @PutMapping
    @PreAuthorize("hasAuthority('sys:advertising:update')")
    @Log(type = SysLogTypeConstant.ADVERTISING, businessType = BusinessTypeEnum.UPDATE)
    public ResponseInfo updateAdvertising(@Validated @RequestBody AdvertisingCommand command) {
        return advertisingService.updateAdvertising(command);
    }

    /**
     * 批量删除广告位配置
     *
     * @author: Yang false
     * @date: 2023-06-15
     * @version: 1.0.0
     */
    @DeleteMapping("/{ids}" )
    @PreAuthorize("hasAuthority('sys:advertising:remove')")
    @Log(type = SysLogTypeConstant.ADVERTISING, businessType = BusinessTypeEnum.DELETE)
    public ResponseInfo removeAdvertisingByIds(@PathVariable List<Long> ids) {
        return advertisingService.removeAdvertisingByIds(ids);
    }

}
